# menupresenter.py
# note: this should contain no application logic betweens delegating UI events to controllers
#     in case that the UI event is trivial (no validation, etc), presenter is allowed to call
#     the controller API directly
import wx
from pysage import Actor, ActorManager

omanager = ActorManager.get_singleton()

class MenuPresenter(Actor):
    '''this acts between controllers and the viewers, for delegating events'''
    def manage_albums(self, evt):
        lst = omanager.find('mapi').get_registered_paths()

        dlg = wx.MultiChoiceDialog(omanager.find('window'), 'Current folders managed:', "list of folders", lst)

        if (dlg.ShowModal() == wx.ID_OK):
            selections = dlg.GetSelections()
            strings = [lst[x] for x in selections]
            self.log.write("Selections: %s -> %s\n" % (selections, strings))

        dlg.Destroy()
    def online(self, evt):
        omanager.find('servercontroller').online()
    def offline(self, evt):
        omanager.find('servercontroller').offline()
    def toggle_shell(self, evt):
        if omanager.find('window').shell.IsShown():
            omanager.find('window').shell.Hide()
        else:
            omanager.find('window').shell.Show()
        omanager.find('window').center_box.Layout()
    def add_user(self, evt):
        dlg = wx.TextEntryDialog(omanager.find('window'), 'Provide user email address:','Add User')
        if dlg.ShowModal() == wx.ID_OK:
            # should do validation with server later
            omanager.find('mapi').add_user(dlg.GetValue())

        dlg.Destroy()
        return True
    def add_folder(self, evt):
        # In this case we include a "New directory" button. 
        dlg = wx.DirDialog(omanager.find('window'), "Choose a folder that contains photos:",
                          style=wx.DD_DEFAULT_STYLE
                           #| wx.DD_DIR_MUST_EXIST
                           #| wx.DD_CHANGE_DIR
                           )

        # If the user selects OK, then we process the dialog's data.
        # This is done by getting the path data from the dialog - BEFORE
        # we destroy it. 
        if dlg.ShowModal() == wx.ID_OK:
            _path = dlg.GetPath()
            omanager.find('menucontroller').add_folder(_path)
    
        # Only destroy a dialog after you're done with it.
        dlg.Destroy()        
    def manage_viewers(self, evt):
        lst = omanager.find('mapi').get_viewer_names()

        dlg = wx.MultiChoiceDialog(omanager.find('window'), 
                                   "Pick some fruit from\nthis list",
                                   "wx.MultiChoiceDialog", lst)

        if (dlg.ShowModal() == wx.ID_OK):
            selections = dlg.GetSelections()
            strings = [lst[x] for x in selections]

        dlg.Destroy()
    def close(self, evt):
        return omanager.find('albumcontroller').close()
    
    